<?php

namespace app\base\model\member;

use app\common\model\CommonModel;



class MemberBalanceModel extends CommonModel{

    protected  $name = 'base_member_balance';

    protected  $pk   = 'member_balance_id';

    

    public function getBalanceSumByMemberId($memberIds,$type = 0){

       $where = [

            ['member_id','IN',$memberIds],

       ];

       $now_time = time();

       if($type == 1){

           $where [] =  ['valid_bg_time','<=',$now_time];

       }else if($type == 2){

           $where [] =  ['valid_bg_time','>',$now_time];

       }

       $datas = $this->field('member_id,SUM(remain_balance) AS balance')->where($where)->group('member_id')->select();

       $return = [];

       foreach($datas as $val){

           $return[$val['member_id']] = $val['balance'];

       }

       return $return;

    }

    

}

